# Date Format
$format = "%d/%m/%Y"
# $format = "%m/%d/%Y" # Will display: month/day/year


# Shell UI
$shellui = $Host.UI.RawUI

# $shellui.WindowTitle = "Powershell"
# $shellui.BackgroundColor = "Background Color"
# $shellui.ForegroundColor = "Foreground Color"

# Hashes
function md5 {Get-FileHash -Algorithm MD5 $args}
function sha1 {Get-FileHash -Algorithm SHA1 $args}
function sha256 {Get-FileHash -Algorithm SHA256 $args}
function sha384 {Get-FileHash -Algorithm SHA384 $args}
function sha512 {Get-FileHash -Algorithm SHA512 $args}

# Base64 Dec & Enc
function b64-dec {[Text.Encoding]::Utf8.GetString([Convert]::FromBase64String($args))}
function b64-enc {[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($args))}

# Others
function ytdwn($url) {
    $req = "https://maadhav-ytdl.herokuapp.com/video_info.php?url=$($url)"
    $get = Invoke-WebRequest -Uri $req
    $json = ConvertFrom-Json $get.content
    Write-Host "Saving at video.mp4" -ForegroundColor DarkMagenta
    Invoke-WebRequest -URI $json.links[0] -OutFile video.mp4
}

function profile {notepad $PROFILE}

function weather {Invoke-RestMethod https://wttr.in/?format=4}
function date {Get-Date -UFormat "$format"}
function time {Get-Date -UFormat "%R"}

# Console services & api clients
function myip {Invoke-RestMethod https://eth0.me}
function shorturl($url) {Invoke-RestMethod "https://is.gd/create.php?format=simple&url=$($url)"}
function number($nmb) {Invoke-RestMethod "http://numbersapi.com/$($nmb)"}

# Only on windows
function user {$Env:username}
function computer {(Get-CimInstance -ClassName Win32_ComputerSystem).Name}
function system {(Get-WmiObject Win32_OperatingSystem).Caption}
function ver {(Get-WmiObject Win32_OperatingSystem).version}

# Aliases
Set-Alias -Name grep -Value Select-String